package org.ushio.nchu_22201406.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.ushio.nchu_22201406.dao.balanceDao;
import org.ushio.common_module.entity.PhoneBillRecord;
import org.ushio.nchu_22201406.service.balanceService;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@Service
public class balanceServiceImpl implements balanceService {
    @Autowired
    private balanceDao balanceDao;
    @Override
    public void updateBalance(String phoneNumber, BigDecimal amount) {
        balanceDao.updateBalanceByPhoneNumber(phoneNumber, amount);
        // 生成充值记录
        PhoneBillRecord record = new PhoneBillRecord();
        record.setPhoneNumber(phoneNumber);
        record.setBillAmount(amount.doubleValue()); // 转换为double类型存储
        record.setBillDate(new java.sql.Date(System.currentTimeMillis())); // 当前日期
        record.setPaymentStatus(1); // 假设1表示支付成功

        // 插入充值记录
        balanceDao.insertPhoneBillRecord(record.getPhoneNumber(),
                BigDecimal.valueOf(record.getBillAmount()),
                record.getBillDate(),
                (int) record.getPaymentStatus());
    }
}
